package com.mall.module.system.service.Impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.mall.module.system.domain.entity.SysLoginLog;
import com.mall.module.system.mapper.SysLoginLogMapper;
import com.mall.module.system.service.SysLoginLogService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.Date;
import java.util.List;

/**
 * 系统登录日志服务实现类
 */
@Service
public class SysLoginLogServiceImpl implements SysLoginLogService {

    @Autowired
    private SysLoginLogMapper loginLogMapper;

    @Override
    public PageInfo<SysLoginLog> listLoginLogPage(Integer pageNum, Integer pageSize, String username, 
                                                Integer status, Date startTime, Date endTime) {
        PageHelper.startPage(pageNum, pageSize);
        List<SysLoginLog> list = loginLogMapper.selectLoginLogList(username, status, startTime, endTime);
        return new PageInfo<>(list);
    }

    @Override
    public SysLoginLog getLoginLogById(Long id) {
        return loginLogMapper.selectLoginLogById(id);
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public boolean addLoginLog(SysLoginLog loginLog) {
        return loginLogMapper.insertLoginLog(loginLog) > 0;
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public boolean deleteLoginLog(Long id) {
        return loginLogMapper.deleteLoginLogById(id) > 0;
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public boolean deleteLoginLogByIds(List<Long> ids) {
        return loginLogMapper.deleteLoginLogByIds(ids) > 0;
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public boolean cleanLoginLog() {
        return loginLogMapper.cleanLoginLog() > 0;
    }
} 